package cn.edu.scau.cmi.lijiongtao.client;

import cn.edu.scau.cmi.lijiongtao.consistentComposite.China;
import cn.edu.scau.cmi.lijiongtao.consistentComposite.USA;
import cn.edu.scau.cmi.lijiongtao.consistentComposite.UnitedNations;
import cn.edu.scau.cmi.lijiongtao.consistentComposite.WorldOrganization;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class consistentCompositeClient extends Application{
	public static void main(String[] args) {
		launch(args);
	}

	@Override
	public void start(Stage primaryStage) throws Exception {
		primaryStage.setTitle("实验五：一致性组合模式");
		primaryStage.setHeight(400);
		primaryStage.setWidth(600);
		
		Label label = new Label("Country:");
		ChoiceBox<String> choiceBox = new ChoiceBox<String>();
		choiceBox.setItems(FXCollections.observableArrayList(
				"中国", "USA", "联合国"));
		choiceBox.setValue("中国");
		HBox hBox = new HBox();
		hBox.setPadding(new Insets(15, 5, 5, 5));
		hBox.setSpacing(10);
		hBox.getChildren().addAll(label, choiceBox);
		
		Button button = new Button("Say Hello");
		
		VBox vBox = new VBox();
		vBox.setPadding(new Insets(15, 5, 5, 5));
		vBox.setSpacing(20);
		vBox.getChildren().addAll(hBox, button);
		
		TextArea textArea = new TextArea("");
		BorderPane bp = new BorderPane();
		bp.setTop(textArea);
		bp.setCenter(vBox);
		
		Scene s = new Scene(bp,480,600);
		primaryStage.setScene(s);
		primaryStage.show();
		
		button.setOnAction(e -> {
			WorldOrganization wo = null;
			String type = choiceBox.getSelectionModel().getSelectedItem();
			if(type.equals("中国")) { wo = new China();}
			else if(type.equals("USA")) { wo = new USA();}
			else if(type.equals("联合国")) { wo = new UnitedNations();}
			String hello = wo.say();
			textArea.setText(hello);
		});
	}

}
